package com.ew.gerocomium.controller;


import com.ew.gerocomium.common.constant.Constant;
import com.ew.gerocomium.dao.base.Result;
import com.ew.gerocomium.dao.query.AddNoticeQuery;
import com.ew.gerocomium.dao.query.OperateSourceQuery;
import com.ew.gerocomium.dao.query.PageNoticeByKeyQuery;
import com.ew.gerocomium.dao.query.PageSourceByKeyQuery;
import com.ew.gerocomium.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "公告管理")
@RestController
@PreAuthorize("@AuthorityAssert.hasAuthority('/notice/all')")
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    private NoticeService noticeService;

    @GetMapping("/listAllNotice")
    @ApiOperation(value = "分页查询公告", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result pageSourceByKey(@ApiParam(value = "分页查询公告请求实体", required = true) PageNoticeByKeyQuery pageSourceByKeyQuery,
                                  @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return noticeService.pageNoticeByKey(pageSourceByKeyQuery);
    }
    @PostMapping("/addNotice")
    @ApiOperation(value = "新增公告", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result addNotice(@ApiParam(value = "新增通知请求参数", required = true) @RequestBody AddNoticeQuery addNoticeQuery,
                            @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return noticeService.addNotice(addNoticeQuery.getTitle(), addNoticeQuery.getContent());
    }

    @PostMapping("/deltNotice")
    @ApiOperation(value = "删除公告", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result deltNotice(@ApiParam(value = "删除公告请求参数", required = true) @RequestBody AddNoticeQuery addNoticeQuery,
                            @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return noticeService.delNotice(addNoticeQuery.getId());
    }

}
